// JavaScript Document
// 

window.onload = function(){
	var a_adImages = document.getElementById("a_link_adImages");
	var img_adImages = document.getElementById("img_adImages");
	var ul_imgSel = document.getElementById("imgSelTab");
	li_imgs = ul_imgSel.childNodes;

	// 临时方案
	var imgs = ["http://127.0.0.1/vancl/Static/Index/images/jiaodiandd.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/sjpbt.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/sj2.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/msjd.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/vtsj.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/polosj.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/v7.jpg",
				"http://127.0.0.1/vancl/Static/Index/images/v8.jpg"];
	
	var index = 0;
	var iLastIndex = -1;

	var changing = true;

	setADImg(0);

	function setADImg(index){
		img_adImages.setAttribute("src", imgs[index]);

		li_imgs[index].style.background = "#A10000";
		if (iLastIndex != -1 && iLastIndex != index){
			li_imgs[iLastIndex].style.background = "#1E1E1E";
		}
		iLastIndex = index;
	}

	li_imgs[0].onmouseover = function(){
		changing = false;
		setADImg(0);
		index = 0;
	}
	li_imgs[1].onmouseover = function(){
		changing = false;
		setADImg(1);
		index = 1;
	}
	li_imgs[2].onmouseover = function(){
		changing = false;
		setADImg(2);
		index = 2;
	}
	li_imgs[3].onmouseover = function(){
		changing = false;
		setADImg(3);
		index = 3;
	}
	li_imgs[4].onmouseover = function(){
		changing = false;
		setADImg(4);
		index = 4;
	}
	li_imgs[5].onmouseover = function(){
		changing = false;
		setADImg(5);
		index = 5;
	}
	li_imgs[6].onmouseover = function(){
		changing = false;
		setADImg(6);
		index = 6;
	}
	li_imgs[7].onmouseover = function(){
		changing = false;
		setADImg(7);
		index = 7;
	}

	for (var i=0; i<li_imgs.length; i++){
		// li_imgs[i].onmouseover = function(){
		// 	changing = false;
		// 	setADImg(i);
		// }
		li_imgs[i].onmouseout = function(){
			changing = true;
		}
	}

	function run(){
		if (!changing){
			return;
		}

		index++;
		if (index==8){
			index = 0;
		}

		setADImg(index);
	}

	setInterval(run, 3000);
}